home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / labeldisk / RCS / labeldisk.c,v < prev    next >
Encoding:
Text File  |  1992-09-08  |  62.5 KB  |  2,539 lines

  1. head     1.15;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    shirriff:1.15; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.15
  10. date     92.02.06.12.05.21;  author voelker;  state Exp;
  11. branches ;
  12. next     1.14;
  13.  
  14. 1.14
  15. date     91.10.30.13.08.01;  author pmchen;  state Exp;
  16. branches ;
  17. next     1.13;
  18.  
  19. 1.13
  20. date     91.09.26.21.06.18;  author voelker;  state Exp;
  21. branches ;
  22. next     1.12;
  23.  
  24. 1.12
  25. date     91.09.26.20.36.41;  author voelker;  state Exp;
  26. branches ;
  27. next     1.11;
  28.  
  29. 1.11
  30. date     91.09.14.14.03.55;  author voelker;  state Exp;
  31. branches ;
  32. next     1.10;
  33.  
  34. 1.10
  35. date     91.09.14.13.54.39;  author voelker;  state Exp;
  36. branches ;
  37. next     1.9;
  38.  
  39. 1.9
  40. date     91.09.14.13.39.21;  author voelker;  state Exp;
  41. branches ;
  42. next     1.8;
  43.  
  44. 1.8
  45. date     90.06.28.15.13.49;  author jhh;  state Exp;
  46. branches ;
  47. next     1.7;
  48.  
  49. 1.7
  50. date     90.02.16.16.11.43;  author shirriff;  state Exp;
  51. branches ;
  52. next     1.6;
  53.  
  54. 1.6
  55. date     90.01.11.17.13.40;  author jhh;  state Exp;
  56. branches ;
  57. next     1.5;
  58.  
  59. 1.5
  60. date     90.01.11.15.11.41;  author jhh;  state Exp;
  61. branches ;
  62. next     1.4;
  63.  
  64. 1.4
  65. date     89.08.01.23.32.23;  author jhh;  state Exp;
  66. branches ;
  67. next     1.3;
  68.  
  69. 1.3
  70. date     89.08.01.23.27.56;  author jhh;  state Exp;
  71. branches ;
  72. next     1.2;
  73.  
  74. 1.2
  75. date     89.06.19.14.34.44;  author jhh;  state Exp;
  76. branches ;
  77. next     1.1;
  78.  
  79. 1.1
  80. date     88.12.05.10.02.06;  author brent;  state Exp;
  81. branches ;
  82. next     ;
  83.  
  84.  
  85. desc
  86. @Program to read and possibly change a disk label
  87. @
  88.  
  89.  
  90. 1.15
  91. log
  92. @if labeldisk tries to write the label to all partitions on a new
  93. disk that does not have filesystems on it, then it cannot check to
  94. see if the partitions are valid when copying a label from another
  95. disk.  changed it to just write the raw disk, and then exit.
  96. @
  97. text
  98. @/* 
  99.  * labeldisk.c --
  100.  *
  101.  *    Read and possibly change the disk label.
  102.  *
  103.  * Copyright (C) 1986 Regents of the University of California
  104.  * All rights reserved.
  105.  */
  106.  
  107. #ifndef lint
  108. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.14 91/10/30 13:08:01 pmchen Exp Locker: voelker $ SPRITE (Berkeley)";
  109. #endif not lint
  110.  
  111. #include <sprite.h>
  112. #include "option.h"
  113. #include "disk.h"
  114. #include <sys/file.h>
  115. #include <stdio.h>
  116. #include <errno.h>
  117. #include <kernel/dev.h>
  118.  
  119. #define Min(a,b) (((a) < (b)) ? (a) : (b))
  120. /*
  121.  * Constants settable via the command line.
  122.  */
  123. char *fromName;         /* e.g. set to "/dev/rsd0" */
  124. char *toName;        /* e.g. set to "/dev/rsd0g" */
  125. Boolean writeLabel = FALSE;
  126. Boolean writeSun = FALSE;
  127. Boolean writeDec = FALSE;
  128. Boolean newLabel = FALSE;
  129. Boolean writeQuick = FALSE;
  130.  
  131. Option optionArray[] = {
  132.     {OPT_DOC,"",(Address)NIL,
  133.     "labeldisk [-from fromDevice] [-w] [-q] [-sun] [-dec] [-new] toDevice"},
  134.     {OPT_STRING, "from", (char *)&fromName,
  135.     "Read the disk label from this partition"},
  136.     {OPT_TRUE, "w", (Address)&writeLabel,
  137.     "Write a new disk label"},
  138.     {OPT_TRUE, "sun", (Address)&writeSun,
  139.     "Write a Sun label"},
  140.     {OPT_TRUE, "dec", (Address)&writeDec,
  141.     "Write a Dec label"},
  142.     {OPT_TRUE, "new", (Address)&newLabel,
  143.     "Ignore any old label"},
  144.     {OPT_TRUE, "q", (Address)&writeQuick,
  145.     "Copy label quickly, without prompting to change the label"}
  146. };
  147. int numOptions = sizeof(optionArray) / sizeof(Option);
  148.  
  149. static ReturnStatus    LabelDisk();
  150. static void        EditLabel();
  151. static void        InputNumber();
  152. static int        IsYes();
  153.  
  154. /*
  155.  *----------------------------------------------------------------------
  156.  *
  157.  * main --
  158.  *
  159.  *    Open the disk device and call LabelDisk.
  160.  *
  161.  * Results:
  162.  *    None.
  163.  *
  164.  * Side effects:
  165.  *    None.
  166.  *
  167.  *----------------------------------------------------------------------
  168.  */
  169. main(argc, argv)
  170.     int argc;
  171.     char *argv[];
  172. {
  173.     int openFlags;
  174.     int toStreamID;
  175.     int fromStreamID;
  176.     int tmp;
  177.  
  178.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  179.     if (argc != 2) {
  180.     if (argc == 1 && fromName != NULL && strlen(fromName) > 0) {
  181.         toName = fromName;
  182.     } else {
  183.         Opt_PrintUsage(argv[0], optionArray, numOptions);
  184.         exit(FAILURE);
  185.     }
  186.     } else {
  187.     if (fromName == NULL || strlen(fromName) == 0) {
  188.         fromName = argv[1];
  189.     }
  190.     toName = argv[1];
  191.     } 
  192.     if (writeSun || writeDec || writeQuick) {
  193.     writeLabel = TRUE;
  194.     }
  195.     if (writeLabel) {
  196.     openFlags = O_RDWR;
  197.     } else {
  198.     openFlags = O_RDONLY;
  199.     }
  200.     if ((writeSun?1:0)+(writeDec?1:0) > 1) {
  201.     fprintf(stderr,
  202.         "Can't specify more than one of -sun, -dec.\n");
  203.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  204.     exit(FAILURE);
  205.     } 
  206.     fromStreamID = open(fromName, openFlags, 0);
  207.     if (fromStreamID < 0) {
  208.     perror("Can't open device");
  209.     exit(FAILURE);
  210.     }
  211.     tmp = strcmp(fromName, toName);
  212.     if (tmp) {
  213.     toStreamID = open(toName, openFlags, 0);
  214.     if (toStreamID < 0) {
  215.         perror("Can't open device");
  216.         exit(FAILURE);
  217.     }
  218.     } else {
  219.     toStreamID = fromStreamID;
  220.     }
  221.     if (LabelDisk(fromStreamID, toStreamID) != SUCCESS) {
  222.     if (errno == 0) {
  223.         fprintf(stderr, "labeldisk: Short read, or EOF encountered ");
  224.         fprintf(stderr, "on most likely an empty partition.\n");
  225.     } else {
  226.         perror("labeldisk");
  227.     }
  228.     }
  229.     exit(errno);
  230. }
  231.  
  232. /*
  233.  *----------------------------------------------------------------------
  234.  *
  235.  * LabelDisk --
  236.  *    Read and perhaps write the disk label.
  237.  *
  238.  * Results:
  239.  *    A status.
  240.  *
  241.  * Side effects:
  242.  *    Rewrites the partition information on the 0'th sector of the disk.
  243.  *
  244.  *----------------------------------------------------------------------
  245.  */
  246. static ReturnStatus
  247. LabelDisk(fromStreamID, toStreamID)
  248.     int fromStreamID;            /* Handle on raw input disk */
  249.     int toStreamID;                     /* Handle on raw output disk */
  250. {
  251.     Disk_Label             *diskLabelPtr;
  252.     int             n;
  253.     char             answer[80];
  254.     Disk_NativeLabelType    inLabel, outLabel;
  255.     static char                 buffer[1024], buffer2[1024];
  256.     ReturnStatus        status;
  257.     Ofs_DomainHeader            *headerPtr;
  258.  
  259.     if (writeSun) {
  260.     outLabel = DISK_SUN_LABEL;
  261.     } else if (writeDec) {
  262.     outLabel = DISK_DEC_LABEL;
  263.     } else {
  264.     outLabel = DISK_NO_LABEL;
  265.     }
  266.     diskLabelPtr = Disk_ReadLabel(fromStreamID);
  267.     if (newLabel || diskLabelPtr == NULL) {
  268.     if (!newLabel) {
  269.         printf("The disk does not have a label.\n");
  270.     }
  271.     if (!writeLabel) {
  272.         return FAILURE;
  273.     }
  274.     if (outLabel == DISK_NO_LABEL) {
  275.         printf("You must specify the -sun, or -dec option.\n");
  276.         return FAILURE;
  277.     }
  278.     inLabel = DISK_NO_LABEL;
  279.     diskLabelPtr = Disk_NewLabel(outLabel);
  280.     }
  281.     if (diskLabelPtr != NULL) {
  282.     inLabel = diskLabelPtr->labelType;
  283.     }
  284.     if (outLabel == DISK_NO_LABEL) {
  285.     outLabel = inLabel;
  286.     }
  287.     Disk_PrintLabel(diskLabelPtr);
  288.     if (!writeLabel) {
  289.     return SUCCESS;
  290.     }
  291.     if (inLabel != outLabel) {
  292.     /*
  293.      * At this point, the output label should be an empty buffer.
  294.      * diskHeaderPointer should be a valid label or empty buffer.
  295.      * diskInfoPtr should be have the proper sector values and string.
  296.      */
  297.     printf(
  298.       "Do you really want to replace a %s label with a %s label? (y/n) ",
  299.       Disk_GetLabelTypeName(inLabel), Disk_GetLabelTypeName(outLabel));
  300.     n = scanf("%s", answer);
  301.     if (n == EOF) {
  302.         exit(1);
  303.     }
  304.     if (strcasecmp(answer, "y")) {
  305.         exit(1);
  306.     }
  307.     }
  308.     if (!writeQuick) {
  309.     EditLabel(toStreamID, diskLabelPtr);
  310.     } else {
  311.     printf("\nCommit label? (y/n) ");
  312.     if (!IsYes()) {
  313.         exit(0);
  314.     }
  315.     }
  316.     if (inLabel != outLabel && fromStreamID == toStreamID) {
  317.     status = Disk_EraseLabel(fromStreamID, inLabel);
  318.     if (status != SUCCESS) {
  319.         printf("Unable to erase old label.\n");
  320.     }
  321.     }
  322.     printf("Write this label to all valid partitions? (y/n) ");
  323.     n = scanf("%s", answer);
  324.     if ((n == EOF) || strcasecmp(answer, "y")) {
  325.     printf("Writing disk label to %s.\n", toName);
  326.     status = Disk_WriteLabel(toStreamID, diskLabelPtr, outLabel);
  327.     return status;
  328.     } else {
  329.     int part, cyls, streamID, len, cantWriteToRawDisk = FALSE;
  330.     char c, *devName;
  331.  
  332.     len = strlen(toName);
  333.     devName = (char *)malloc(sizeof(char) * len + 1);
  334.         if (devName == NULL) {
  335.         perror("allocating string");
  336.         exit(FAILURE);
  337.     }
  338.     c = toName[len - 1];
  339.     if (c >= 'a' && c < 'i') {
  340.         /*
  341.          * the original destination name is a partition, 
  342.          * e.g. "/dev/rsd00a", so make sure to write the label
  343.          * to the beginning of the raw disk and then
  344.          * write the label to all valid partitions
  345.          */
  346.         sprintf(devName, "%s",toName);
  347.         devName[--len] = '\0';  
  348.         streamID = open(devName, O_RDWR, 0);
  349.     } else {
  350.         /*
  351.          * the original destination name is a raw disk,
  352.          * e.g. "/dev/rsd00", so write the label to the raw
  353.          * disk and then to all valid partitions
  354.          */
  355.         sprintf(devName, "%s",toName);
  356.         streamID = toStreamID;
  357.     }
  358.     printf("raw device: %s\n", devName);
  359.     if (streamID >= 0) {
  360.         status = Disk_WriteLabel(streamID, diskLabelPtr, outLabel);
  361.         if (status != SUCCESS) {
  362.         printf("Unable to write disk label to ");
  363.         printf("%s...skipping\n", devName);
  364.         cantWriteToRawDisk = TRUE;
  365.         }
  366.     } else {
  367.         cantWriteToRawDisk = TRUE;
  368.     }
  369.     devName[len + 1] = '\0';
  370.     for (part = 0 ; part < diskLabelPtr -> numPartitions; part++) {
  371.         cyls = diskLabelPtr->partitions[part].numCylinders;
  372.         if (cyls <= 0) {
  373.         continue;
  374.         }
  375.         devName[len] = 'a' + part;
  376.         printf("partition: %s\n", devName);
  377.         if (!strcmp(devName, fromName)) {
  378.         streamID = fromStreamID;
  379.         } else if (!strcmp(devName, toName)) {
  380.         streamID = toStreamID;
  381.         } else {
  382.         streamID = open(devName, O_RDWR, 0);
  383.         if (streamID < 0) {
  384.             perror("Can't open device");
  385.             exit(FAILURE);
  386.         }
  387.         }
  388.         status = Disk_HasFilesystem(streamID, diskLabelPtr);
  389.         if (status == DISK_HAS_NO_FS) {
  390.         printf("Could not find file system on ");
  391.         printf("%s...skipping\n", devName);
  392.         continue;
  393.         }
  394.         status = Disk_WriteLabel(streamID, diskLabelPtr, outLabel);
  395.         if (status) {
  396.         printf("Unable to write disk label to ");
  397.         printf("%s...skipping\n", devName);
  398.         } else {
  399.         /*
  400.          * Having written to the partition, if the partition
  401.          * starts at cylinder 0 then we have effectively
  402.          * written to the raw disk
  403.          */
  404.         if (diskLabelPtr->partitions[part].firstCylinder == 0) {
  405.             cantWriteToRawDisk = FALSE;
  406.         }
  407.         }
  408.     }
  409.     if (cantWriteToRawDisk == TRUE) {
  410.         devName[len] = '\0';
  411.         printf("Warning:  either couldn't open and write to");
  412.         printf("%s or\ncouldn't write to a valid partition ", devName);
  413.         printf("that starts at cylinder 0.\n");
  414.     }
  415.     }
  416. }
  417.  
  418. /*
  419.  *----------------------------------------------------------------------
  420.  *
  421.  * EditLabel --
  422.  *
  423.  *    Interactively edits the disk label.
  424.  *
  425.  * Results:
  426.  *    None.
  427.  *
  428.  * Side effects:
  429.  *    Changes contents of the disk label.
  430.  *
  431.  *----------------------------------------------------------------------
  432.  */
  433. static void
  434. EditLabel(streamID, labelPtr)
  435.     int            streamID;    /* Handle on raw disk */
  436.     Disk_Label        *labelPtr;    /* The disk label */
  437. {
  438.     int                 numHeads, numSectors, part;
  439.     ReturnStatus        status = SUCCESS;
  440.     int                 first, cyls, last, lastSector, lastCyl;
  441.     char            buffer[DEV_BYTES_PER_SECTOR];
  442.     char        *tmpPtr;
  443.     int            labelLen;
  444.  
  445. editLabel:
  446.     printf("Size of ascii label (%d): ", labelPtr->asciiLabelLen);
  447.     InputNumber(&labelPtr->asciiLabelLen);
  448.     printf("ascii label (%s): ", labelPtr->asciiLabel);
  449.     tmpPtr = fgets(buffer, labelPtr->asciiLabelLen,stdin);
  450.     if (tmpPtr == NULL) {
  451.     exit(1);
  452.     }
  453.     printf("%d\n", strlen(buffer));
  454.     if (strlen(buffer) > 1) {
  455.     labelLen = Min(strlen(buffer), labelPtr->asciiLabelLen);
  456.     strncpy(labelPtr->asciiLabel, buffer, labelLen);
  457.     labelPtr->asciiLabel[labelLen - 1] = '\0';
  458.     }
  459.     printf("Number of heads (%d): ", labelPtr->numHeads);
  460.     InputNumber(&labelPtr->numHeads);
  461.     printf("Number of sectors per track (%d): ", labelPtr->numSectors);
  462.     InputNumber(&labelPtr->numSectors);
  463.     printf("Number of cylinders (%d): ", labelPtr->numCylinders);
  464.     InputNumber(&labelPtr->numCylinders);
  465.     printf("Number of alternate cylinders (%d): ", labelPtr->numAltCylinders);
  466.     InputNumber(&labelPtr->numAltCylinders);
  467.     printf("Starting sector of summary info (%d): ", labelPtr->summarySector);
  468.     InputNumber(&labelPtr->summarySector);
  469.     printf("Starting sector of boot program (%d): ", labelPtr->bootSector);
  470.     InputNumber(&labelPtr->bootSector);
  471.     printf("Number of boot sectors (%d): ", labelPtr->numBootSectors);
  472.     InputNumber(&labelPtr->numBootSectors);
  473.     printf("Starting sector of domain header (%d): ", labelPtr->domainSector);
  474.     InputNumber(&labelPtr->domainSector);
  475.     numHeads = labelPtr->numHeads;
  476.     numSectors = labelPtr->numSectors;
  477.     if (numHeads * numSectors != 
  478.     labelPtr->numHeads * labelPtr->numSectors) {
  479.     printf(
  480.     "The size of a cylinder changed so I have to zero the partition map.\n");
  481.     for (part=0 ; part < labelPtr->numPartitions; part++) {
  482.         labelPtr->partitions[part].firstCylinder = 0;
  483.         labelPtr->partitions[part].numCylinders = 0;
  484.     }
  485.     }
  486.     for (part=0 ; part < labelPtr->numPartitions; part++) {
  487.     first = labelPtr->partitions[part].firstCylinder;
  488.     cyls = labelPtr->partitions[part].numCylinders;
  489.     last = (cyls > 0) ? (cyls + first - 1) : first;
  490.     printf("\n%c: First %4d Last %4d Num %4d (%7d sectors)\n",
  491.         'a' + part, first, last, cyls,
  492.         cyls *  labelPtr->numHeads * labelPtr->numSectors);
  493.     printf("First (%d): ", labelPtr->partitions[part].firstCylinder);
  494.     InputNumber(&labelPtr->partitions[part].firstCylinder);
  495.     printf("Num (%d): ", labelPtr->partitions[part].numCylinders);
  496.     InputNumber(&labelPtr->partitions[part].numCylinders);
  497.     }
  498.     lastCyl = 0;
  499.     printf("\nNew Label\n");
  500.     Disk_PrintLabel(labelPtr);
  501.     lastSector = (lastCyl + 1) * numHeads * numSectors - 1;
  502.     status = Disk_SectorRead(streamID, lastSector, 1, buffer);
  503.     if (status != 0) {
  504.     printf("I couldn't read the last sector (sector %d)!!!\n", lastSector);
  505.     printf("Either the disk isn't as big as you think it is,\n");
  506.     printf("or the device is not a raw device.\n");
  507.     }
  508.     printf("\nCommit new label? (y/n) ");
  509.     if (!IsYes()) {
  510.     printf("Try again\n");
  511.     goto editLabel;
  512.     }
  513. }
  514.  
  515. /*
  516.  *----------------------------------------------------------------------
  517.  *
  518.  * InputNumber --
  519.  *
  520.  *    Get a number interactively.
  521.  *
  522.  * Results:
  523.  *    None.
  524.  *
  525.  * Side effects:
  526.  *    Stuff is read from stdin..
  527.  *
  528.  *----------------------------------------------------------------------
  529.  */
  530. static void
  531. InputNumber(number)
  532.     int        *number;    /* Place to store number. */
  533. {
  534.     int n, val;
  535.     char buffer[80];
  536.  
  537.     if (fgets(buffer, 80, stdin) == NULL) {
  538.     exit(1);
  539.     }
  540.     n = sscanf(buffer, "%d", &val);
  541.     if (n < 1) {
  542.     return;
  543.     }
  544.     *number = val;
  545. }
  546.  
  547. /*
  548.  *----------------------------------------------------------------------
  549.  *
  550.  * IsYes --
  551.  *
  552.  *    Returns TRUE if user answers y.
  553.  *
  554.  * Results:
  555.  *    TRUE or FALSE.
  556.  *
  557.  * Side effects:
  558.  *    None.
  559.  *
  560.  *----------------------------------------------------------------------
  561.  */
  562. static int
  563. IsYes()
  564. {
  565.     int n;
  566.     char answer[80];
  567.     n = scanf("%s", answer);
  568.     if (n == EOF) {
  569.     exit(1);
  570.     }
  571.     if (strcmp(answer, "y")==0) {
  572.     return TRUE;
  573.     } else {
  574.     return FALSE;
  575.     }
  576. }
  577. @
  578.  
  579.  
  580. 1.14
  581. log
  582. @*** empty log message ***
  583. @
  584. text
  585. @d11 1
  586. a11 1
  587. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.13 91/09/26 21:06:18 voelker Exp Locker: pmchen $ SPRITE (Berkeley)";
  588. d14 1
  589. a14 1
  590. #include "sprite.h"
  591. a15 3
  592. #include "sys/file.h"
  593. #include "stdio.h"
  594. #include "errno.h"
  595. d17 4
  596. a20 1
  597. #include "kernel/dev.h"
  598. d125 6
  599. a130 1
  600.     perror("labeldisk");
  601. a224 1
  602.  
  603. a228 6
  604.     headerPtr = Disk_ReadDomainHeader(toStreamID, diskLabelPtr);
  605.     if (headerPtr == NULL) {
  606.         printf("Could not read OFS domain header of ");
  607.         printf("%s\n", toName);
  608.         return -2; 
  609.     }
  610. d263 3
  611. a265 3
  612.         status = Disk_HasFilesystem(streamID, diskLabelPtr);
  613.         if (status == DISK_HAS_NO_FS) {
  614.         printf("Could not find file system on ");
  615. a267 7
  616.         } else {
  617.         status = Disk_WriteLabel(streamID, diskLabelPtr, outLabel);
  618.         if (status) {
  619.             printf("Unable to write disk label to ");
  620.             printf("%s...skipping\n", devName);
  621.             cantWriteToRawDisk = TRUE;
  622.         }
  623. d315 1
  624. a315 1
  625.         printf("%s or\ncouldn't write to a valid partition", devName);
  626. @
  627.  
  628.  
  629. 1.13
  630. log
  631. @extended it to cover lfs file systems too...
  632.  
  633. @
  634. text
  635. @d11 1
  636. a11 1
  637. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.12 91/09/26 20:36:41 voelker Exp Locker: voelker $ SPRITE (Berkeley)";
  638. a370 2
  639.     numHeads = labelPtr->numHeads;
  640.     numSectors = labelPtr->numSectors;
  641. d387 2
  642. @
  643.  
  644.  
  645. 1.12
  646. log
  647. @cleaned up code to Sprite coding standards...
  648.  
  649. @
  650. text
  651. @d11 1
  652. a11 1
  653. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.11 91/09/14 14:03:55 voelker Exp Locker: voelker $ SPRITE (Berkeley)";
  654. d265 3
  655. a267 3
  656.         headerPtr = Disk_ReadDomainHeader(streamID, diskLabelPtr);
  657.         if (headerPtr == NULL) {
  658.         printf("Could not read OFS domain header of ");
  659. d300 3
  660. a302 3
  661.         headerPtr = Disk_ReadDomainHeader(streamID, diskLabelPtr);
  662.         if (headerPtr == NULL) {
  663.         printf("Could not read OFS domain header of ");
  664. @
  665.  
  666.  
  667. 1.11
  668. log
  669. @added query to let user abort
  670. @
  671. text
  672. @d11 1
  673. a11 1
  674. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.10 91/09/14 13:54:39 voelker Exp Locker: voelker $ SPRITE (Berkeley)";
  675. a30 1
  676. Boolean writeSprite = FALSE;
  677. d79 1
  678. d114 2
  679. a115 1
  680.     if (strcmp(fromName, toName)) {
  681. a149 7
  682.     Disk_Label            diskLabel;
  683.     Sun_DiskLabel         *sunLabelPtr;
  684.     Dec_DiskLabel         *decLabelPtr;
  685.     Fsdm_DiskHeader        *diskHeaderPtr;
  686.     Sun_DiskLabel        sunLabel;
  687.     Dec_DiskLabel        decLabel;
  688.     Fsdm_DiskHeader        diskHeader;
  689. d153 1
  690. a153 2
  691.     static char    *labelName[3] = {"Sun", "Sprite", "Dec"};
  692.     static char buffer[1024], buffer2[1024];
  693. d155 1
  694. a163 2
  695.     diskHeaderPtr = (Fsdm_DiskHeader *)buffer;
  696.     decLabelPtr = (Dec_DiskLabel *)buffer2;
  697. d170 1
  698. a170 1
  699.         return(FAILURE);
  700. d174 1
  701. a174 1
  702.         return(FAILURE);
  703. a213 1
  704. /**  check **/
  705. d222 2
  706. a223 1
  707.     if ((scanf("%s", answer) == EOF) || strcasecmp(answer, "y")) {
  708. d225 2
  709. a226 1
  710.     if (Disk_ReadDomainHeader(toStreamID, diskLabelPtr) == NULL) {
  711. d229 1
  712. a229 1
  713.         return -2;  /* error return value of Disk_WriteLabel() */
  714. d238 2
  715. a239 1
  716.     if ((devName = (char *)malloc(sizeof(char) * len + 1)) == NULL) {
  717. d243 2
  718. a244 1
  719.     if ((c = toName[len - 1]) >= 'a' && c < 'i') {
  720. d252 1
  721. a252 1
  722.         devName[--len] = '\0';  /* null out partition designation */
  723. d265 2
  724. a266 1
  725.         if (Disk_ReadDomainHeader(streamID, diskLabelPtr) == NULL) {
  726. d270 7
  727. a276 4
  728.         } else if (Disk_WriteLabel(streamID, diskLabelPtr, outLabel)) {
  729.         printf("Unable to write disk label to ");
  730.         printf("%s...skipping\n", devName);
  731.         cantWriteToRawDisk = TRUE;
  732. d300 2
  733. a301 1
  734.         if (Disk_ReadDomainHeader(streamID, diskLabelPtr) == NULL) {
  735. d306 2
  736. a307 1
  737.         if (Disk_WriteLabel(streamID, diskLabelPtr, outLabel)) {
  738. d350 6
  739. a355 6
  740.     int n, numHeads, numSectors, part;
  741.     ReturnStatus         status = SUCCESS;
  742.     int first, cyls, last, numCyls, lastSector, totalSectors, lastCyl;
  743.     char            buffer[DEV_BYTES_PER_SECTOR];
  744.     char            *tmpPtr;
  745.     int                labelLen;
  746. d477 1
  747. a477 1
  748.     int n, val;
  749. @
  750.  
  751.  
  752. 1.10
  753. log
  754. @forgot to let -q work without having to specify -w...
  755.  
  756. @
  757. text
  758. @d11 1
  759. a11 1
  760. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.9 91/09/14 13:39:21 voelker Exp Locker: voelker $ SPRITE (Berkeley)";
  761. d216 5
  762. @
  763.  
  764.  
  765. 1.9
  766. log
  767. @extended it so that a source device can be specified from which
  768. labels are read, making the second device specified the device
  769. to which the labels are written.
  770.  
  771. added an option that allows the quick copying of one label from
  772. one device/partition to another, skipping the interactive 
  773. partition information.
  774.  
  775. after commiting a label, allows the user to write that label
  776. to all partition on the destination device which have a positive
  777. length and which have a valid filesystem installed on them.
  778.  
  779. @
  780. text
  781. @d11 1
  782. a11 1
  783. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.8 90/06/28 15:13:49 jhh Exp Locker: voelker $ SPRITE (Berkeley)";
  784. d95 1
  785. a95 1
  786.     if (writeSun || writeDec) {
  787. @
  788.  
  789.  
  790. 1.8
  791. log
  792. @totally rewritten.  Uses new Disk library, allows you to create
  793. a label from scratch.
  794. @
  795. text
  796. @d11 1
  797. a11 1
  798. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.7 90/02/16 16:11:43 shirriff Exp $ SPRITE (Berkeley)";
  799. d26 2
  800. a27 1
  801. char *deviceName;        /* ie. set to "/dev/rsd0" */
  802. d33 1
  803. d37 3
  804. a39 1
  805.     "labeldisk [-w] [-sun] [-dec] [-new] rawDevice"},
  806. d48 2
  807. a56 2
  808.  
  809.  
  810. d78 2
  811. a79 1
  812.     int streamID;
  813. d83 12
  814. a94 4
  815.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  816.     exit(FAILURE);
  817.     }
  818.     deviceName = argv[1];
  819. d103 1
  820. a103 1
  821.     if ( (writeSun?1:0)+(writeDec?1:0) > 1) {
  822. d109 2
  823. a110 2
  824.     streamID = open(deviceName, openFlags, 0);
  825.     if (streamID < 0) {
  826. d114 10
  827. a123 1
  828.     if (LabelDisk(streamID) != SUCCESS) {
  829. d144 3
  830. a146 2
  831. LabelDisk(streamID)
  832.     int streamID;            /* Handle on raw disk */
  833. a162 1
  834.  
  835. d172 1
  836. a172 1
  837.     diskLabelPtr = Disk_ReadLabel(streamID);
  838. d214 6
  839. a219 3
  840.     EditLabel(streamID, diskLabelPtr);
  841.     if (inLabel != outLabel) {
  842.     status = Disk_EraseLabel(streamID, inLabel);
  843. d224 98
  844. a321 3
  845.     printf("Writing disk label.\n");
  846.     status = Disk_WriteLabel(streamID, diskLabelPtr, outLabel);
  847.     return status;
  848. a322 1
  849.  
  850. @
  851.  
  852.  
  853. 1.7
  854. log
  855. @Added dec disk label functions, cleaned stuff up.
  856. @
  857. text
  858. @d11 1
  859. a11 1
  860. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.6 90/01/11 17:13:40 jhh Exp Locker: shirriff $ SPRITE (Berkeley)";
  861. d19 1
  862. a19 1
  863. #include "diskUtils.h"
  864. d22 1
  865. d35 1
  866. a35 1
  867.     "labeldisk [-w] [-sun] [-dec] [-sprite] [-new] rawDevice"},
  868. a41 2
  869.     {OPT_TRUE, "sprite", (Address)&writeSprite,
  870.     "Write a Sprite label"},
  871. d47 4
  872. a50 2
  873. extern short SeeSunCheckSum();
  874. extern unsigned int SeeSpriteCheckSum();
  875. a51 10
  876. void    ConvertSunToSprite();
  877. void    ConvertSpriteToSun();
  878. void    ConvertDecToSprite();
  879. void    ConvertSpriteToDec();
  880. ReturnStatus    EraseOldLabel();
  881.  
  882. #define NOLABEL -1
  883. #define SUNLABEL 0
  884. #define SPRITELABEL 1
  885. #define DECLABEL 2
  886. d82 1
  887. a82 1
  888.     if (writeSun || writeSprite || writeDec) {
  889. d90 1
  890. a90 1
  891.     if ( (writeSun?1:0)+(writeSprite?1:0)+(writeDec?1:0) > 1) {
  892. d92 1
  893. a92 1
  894.         "Can't specify more than one of -sun, -dec, -sprite.\n");
  895. d121 1
  896. a121 1
  897. ReturnStatus
  898. d125 2
  899. a126 1
  900.     Disk_Info             *diskInfoPtr;
  901. a129 1
  902.     Disk_Info            diskInfo;
  903. d135 1
  904. a135 1
  905.     int             inLabel, outLabel;
  906. d142 1
  907. a142 1
  908.     outLabel = SUNLABEL;
  909. d144 1
  910. a144 3
  911.     outLabel = DECLABEL;
  912.     } else if (writeSprite) {
  913.     outLabel = SPRITELABEL;
  914. d146 1
  915. a146 1
  916.     outLabel = -1;
  917. d150 2
  918. a151 23
  919.     diskInfoPtr = Disk_ReadDiskInfo(streamID, 0);
  920.     if (!newLabel && diskInfoPtr != (Disk_Info *)0) {
  921.     sunLabelPtr = Disk_ReadSunLabel(streamID);
  922.     if (sunLabelPtr != (Sun_DiskLabel *)0) {
  923.         inLabel = SUNLABEL;
  924.     } else {
  925.         sunLabelPtr = (Sun_DiskLabel *)buffer2;
  926.         diskHeaderPtr = Disk_ReadDiskHeader(streamID);
  927.         if (diskHeaderPtr != (Fsdm_DiskHeader *) 0) {
  928.         inLabel = SPRITELABEL;
  929.         } else {
  930.         diskHeaderPtr = (Fsdm_DiskHeader *)buffer;
  931.         decLabelPtr = Disk_ReadDecLabel(streamID);
  932.         if (decLabelPtr != (Dec_DiskLabel *)0) {
  933.             inLabel = DECLABEL;
  934.         } else {
  935.             fprintf(stderr, "Disk label is neither Sun nor Sprite.\n");
  936.             return(FAILURE);
  937.         }
  938.         }
  939.     }
  940.     } else {
  941.     inLabel = NOLABEL;
  942. d158 2
  943. a159 2
  944.     if (outLabel == NOLABEL) {
  945.         printf("You must specify the -sun, -dec, or -sprite option.\n");
  946. d162 2
  947. a163 19
  948.     bzero(&diskInfo, sizeof(Disk_Info));
  949.     bzero(&sunLabel, sizeof(Sun_DiskLabel));
  950.     bzero(&decLabel, sizeof(Dec_DiskLabel));
  951.     bzero(&diskHeader, sizeof(Fsdm_DiskHeader)); diskInfoPtr = &diskInfo;
  952.     if (outLabel == DECLABEL) {
  953.         diskInfoPtr->bootSector = DEC_BOOT_SECTOR;
  954.         diskInfoPtr->numBootSectors = DEC_LABEL_SECTOR-1;
  955.         diskInfoPtr->summarySector = DEC_SUMMARY_SECTOR;
  956.         diskInfoPtr->domainSector = DEC_DOMAIN_SECTOR;
  957.     } else {
  958.         diskInfoPtr->bootSector = 1;
  959.         diskInfoPtr->numBootSectors = 15;
  960.         diskInfoPtr->summarySector = 17;
  961.         diskInfoPtr->domainSector = 18;
  962.     }
  963.     diskInfoPtr->numDomainSectors = FSDM_NUM_DOMAIN_SECTORS;
  964.     sunLabelPtr = &sunLabel;
  965.     decLabelPtr = &decLabel;
  966.     diskHeaderPtr = &diskHeader;
  967. d165 4
  968. a168 1
  969.     if (outLabel == NOLABEL) {
  970. d171 5
  971. a175 1
  972.     if ((inLabel != outLabel) && (inLabel != NOLABEL)) {
  973. d183 1
  974. a183 1
  975.       labelName[inLabel], labelName[outLabel]);
  976. a190 31
  977.     /*
  978.      * Make input into a Sprite label.  Then change to output label.
  979.      */
  980.     if (inLabel == SUNLABEL) {
  981.         ConvertSunToSprite(diskInfoPtr, sunLabelPtr, diskHeaderPtr);
  982.     } else if (inLabel == DECLABEL) {
  983.         ConvertDecToSprite(diskInfoPtr, decLabelPtr, diskHeaderPtr);
  984.     }
  985.     if (outLabel == SUNLABEL) {
  986.         ConvertSpriteToSun(diskInfoPtr, diskHeaderPtr, sunLabelPtr);
  987.     } else if (outLabel == DECLABEL) {
  988.         ConvertSpriteToDec(diskInfoPtr, diskHeaderPtr, decLabelPtr);
  989.     }
  990.     }
  991.     /*
  992.      * At this point, the output label should be valid.
  993.      */
  994.     if (outLabel == SUNLABEL) {
  995.     status = DoSunLabel(diskInfoPtr, streamID, sunLabelPtr);
  996.     } else if (outLabel == DECLABEL) {
  997.     status = DoDecLabel(diskInfoPtr, streamID, decLabelPtr);
  998.     } else {
  999.     status = DoSpriteLabel(diskInfoPtr, streamID, diskHeaderPtr);
  1000.     }
  1001.     if (status == SUCCESS && inLabel != NOLABEL) {
  1002.     int oldsector, newsector;
  1003.     oldsector = inLabel == DECLABEL ? DEC_LABEL_SECTOR : 0;
  1004.     newsector = outLabel == DECLABEL ? DEC_LABEL_SECTOR : 0;
  1005.     if (oldsector != newsector) {
  1006.         status = EraseOldLabel(streamID, oldsector);
  1007.     }
  1008. d192 5
  1009. a196 59
  1010.     return status;
  1011. }
  1012.  
  1013.  
  1014. /*
  1015.  *----------------------------------------------------------------------
  1016.  *
  1017.  * DoSunLabel --
  1018.  *
  1019.  *    Sets up a Sun label.
  1020.  *
  1021.  * Results:
  1022.  *    None.
  1023.  *
  1024.  * Side effects:
  1025.  *    None.
  1026.  *
  1027.  *----------------------------------------------------------------------
  1028.  */
  1029.  
  1030. ReturnStatus
  1031. DoSunLabel(diskInfoPtr, streamID, sunLabelPtr)
  1032.     Disk_Info            *diskInfoPtr;
  1033.     int                streamID;
  1034.     Sun_DiskLabel         *sunLabelPtr;
  1035. {
  1036.     int             part;
  1037.     ReturnStatus         status = SUCCESS;
  1038.     int                cyls;
  1039.     int                first;
  1040.     int                last;
  1041.     Fsdm_DiskPartition        partitionMap[SUN_NUM_DISK_PARTS];
  1042.  
  1043.     printInfo("SUN", diskInfoPtr);
  1044.  
  1045.     /*
  1046.      * Verify the magic number and the checksum.
  1047.      */
  1048.     if (sunLabelPtr->magic != SUN_DISK_MAGIC) {
  1049.     printf("Bad magic number on disk <%x> not <%x>\n",
  1050.         sunLabelPtr->magic, SUN_DISK_MAGIC);
  1051.     }
  1052.     if (!CheckSunCheckSum(sunLabelPtr)) {
  1053.     printf("Check sum incorrect, 0x%x not 0x%x\n",
  1054.         SeeSunCheckSum(sunLabelPtr), sunLabelPtr->checkSum);
  1055.     }
  1056.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  1057.     first = sunLabelPtr->map[part].cylinder;
  1058.     if (diskInfoPtr->numHeads * diskInfoPtr->numSectors <= 0) {
  1059.         printf("%c: Cylinder %6d NumSectors %6d\n",
  1060.         first, sunLabelPtr->map[part].numBlocks);
  1061.         cyls = 0;
  1062.     } else {
  1063.         cyls = sunLabelPtr->map[part].numBlocks /
  1064.             (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  1065.         last = (cyls > 0) ? (cyls + first - 1) : first;
  1066.         printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  1067.             'a' + part, first, last, cyls,
  1068.             sunLabelPtr->map[part].numBlocks);
  1069. a197 133
  1070.     partitionMap[part].firstCylinder = first;
  1071.     partitionMap[part].numCylinders = cyls;
  1072.     }
  1073.     if (!writeLabel) {
  1074.     return(SUCCESS);
  1075.     }
  1076.     DoNewLabel(diskInfoPtr,partitionMap,SUN_NUM_DISK_PARTS, streamID);
  1077.     strcpy(sunLabelPtr->asciiLabel, diskInfoPtr->asciiLabel);
  1078.     sunLabelPtr->numHeads = diskInfoPtr->numHeads;
  1079.     sunLabelPtr->numSectors = diskInfoPtr->numSectors;
  1080.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  1081.     sunLabelPtr->map[part].cylinder = partitionMap[part].firstCylinder;
  1082.     sunLabelPtr->map[part].numBlocks = partitionMap[part].numCylinders *
  1083.            diskInfoPtr->numHeads * diskInfoPtr->numSectors;
  1084.     }
  1085.     sunLabelPtr->magic = SUN_DISK_MAGIC;
  1086.     MakeSunCheckSum(sunLabelPtr);
  1087.     printf("Writing new sun label\n");
  1088.     status = Disk_SectorWrite(streamID, 0, 1, sunLabelPtr);
  1089.     return status;
  1090. }
  1091.  
  1092. short
  1093. SeeSunCheckSum(sunLabelPtr)
  1094.     Sun_DiskLabel *sunLabelPtr;
  1095. {
  1096.         short *sp, sum = 0;
  1097.         short count = DEV_BYTES_PER_SECTOR/sizeof(short) - 1;
  1098.  
  1099.         sp = (short *)sunLabelPtr;
  1100.         while (count--)
  1101.                 sum ^= *sp++;
  1102.         return (sum);
  1103. }
  1104.  
  1105.  
  1106. CheckSunCheckSum(sunLabelPtr)
  1107.     Sun_DiskLabel *sunLabelPtr;
  1108. {
  1109.         short *sp, sum = 0;
  1110.         short count = DEV_BYTES_PER_SECTOR/sizeof(short);
  1111.  
  1112.         sp = (short *)sunLabelPtr;
  1113.         while (count--)
  1114.                 sum ^= *sp++;
  1115.         return (sum ? 0 : 1);
  1116. }
  1117.  
  1118. MakeSunCheckSum(sunLabelPtr)
  1119.     Sun_DiskLabel *sunLabelPtr;
  1120. {
  1121.         short *sp, sum = 0;
  1122.         short count = DEV_BYTES_PER_SECTOR/sizeof(short) - 1;
  1123.  
  1124.         sunLabelPtr->checkSum = 0;
  1125.         sp = (short *)sunLabelPtr;
  1126.         while (count--)
  1127.                 sum ^= *sp++;
  1128.         sunLabelPtr->checkSum = sum;
  1129. }
  1130.  
  1131. /*
  1132.  *----------------------------------------------------------------------
  1133.  *
  1134.  * DoSpriteLabel --
  1135.  *
  1136.  *    Sets up a Sprite label.
  1137.  *
  1138.  * Results:
  1139.  *    None.
  1140.  *
  1141.  * Side effects:
  1142.  *    None.
  1143.  *
  1144.  *----------------------------------------------------------------------
  1145.  */
  1146.  
  1147. ReturnStatus
  1148. DoSpriteLabel(diskInfoPtr, streamID, diskHeaderPtr)
  1149.     Disk_Info        *diskInfoPtr;
  1150.     int            streamID;
  1151.     Fsdm_DiskHeader    *diskHeaderPtr;
  1152. {
  1153.     int             part;
  1154.     int             n;
  1155.     ReturnStatus         status = SUCCESS;
  1156.     int                blocks;
  1157.     int                first;
  1158.     int                last;
  1159.     int                cyls;
  1160.  
  1161.     printInfo("SPRITE", diskInfoPtr);
  1162.  
  1163.     /*
  1164.      * Verify the magic number and the checksum.
  1165.      */
  1166.     if (diskHeaderPtr->magic != FSDM_DISK_MAGIC) {
  1167.     printf("Bad magic number on disk <%x> not <%x>\n",
  1168.         diskHeaderPtr->magic, FSDM_DISK_MAGIC);
  1169.     }
  1170.     if (!CheckSpriteCheckSum(diskHeaderPtr)) {
  1171.     printf("Check sum incorrect, 0x%x not 0x%x\n",
  1172.         SeeSpriteCheckSum(diskHeaderPtr), FSDM_DISK_MAGIC);
  1173.     }
  1174.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  1175.     first = diskHeaderPtr->map[part].firstCylinder;
  1176.     cyls = diskHeaderPtr->map[part].numCylinders;
  1177.     last = (cyls > 0) ? (cyls + first - 1) : first;
  1178.     blocks = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  1179.         diskHeaderPtr->map[part].numCylinders;
  1180.     printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  1181.         'a' + part, first, last, cyls, blocks);
  1182.     }
  1183.     if (!writeLabel) {
  1184.     return(SUCCESS);
  1185.     }
  1186.     DoNewLabel(diskInfoPtr,diskHeaderPtr->map,SUN_NUM_DISK_PARTS, streamID);
  1187.     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  1188.     strcpy(diskHeaderPtr->asciiLabel, diskInfoPtr->asciiLabel);
  1189.     diskHeaderPtr->numHeads = diskInfoPtr->numHeads;
  1190.     diskHeaderPtr->numSectors = diskInfoPtr->numSectors;
  1191.     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  1192.     diskHeaderPtr->bootSector = diskInfoPtr->bootSector;
  1193.     diskHeaderPtr->numBootSectors = diskInfoPtr->numBootSectors;
  1194.     diskHeaderPtr->domainSector = diskInfoPtr->domainSector;
  1195.     MakeSpriteCheckSum(diskHeaderPtr);
  1196.     printf("Writing new sprite label\n");
  1197.     status = Disk_SectorWrite(streamID, 0, 1, diskHeaderPtr);
  1198.     {
  1199.     FILE *fopen(), *file;
  1200.     file = fopen("label.out","w");
  1201.     fwrite(diskHeaderPtr,512,1,file);
  1202.     fclose(file);
  1203. d199 2
  1204. a203 41
  1205. unsigned int
  1206. SeeSpriteCheckSum(diskHeaderPtr)
  1207.     Fsdm_DiskHeader *diskHeaderPtr;
  1208. {
  1209.         int *sp, sum = 0;
  1210.     int i;
  1211.  
  1212.         sp = (int *)diskHeaderPtr;
  1213.     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  1214.         sum ^= *sp++;
  1215.     }
  1216.         return (sum);
  1217. }
  1218.  
  1219. int
  1220. CheckSpriteCheckSum(diskHeaderPtr)
  1221.     Fsdm_DiskHeader *diskHeaderPtr;
  1222. {
  1223.         int *sp, sum = 0;
  1224.     int i;
  1225.  
  1226.         sp = (int *)diskHeaderPtr;
  1227.     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  1228.         sum ^= *sp++;
  1229.     }
  1230.         return (sum == FSDM_DISK_MAGIC ? 1 : 0);
  1231. }
  1232.  
  1233. MakeSpriteCheckSum(diskHeaderPtr)
  1234.     Fsdm_DiskHeader *diskHeaderPtr;
  1235. {
  1236.         int *sp, sum = 0;
  1237.     int i;
  1238.  
  1239.     diskHeaderPtr->checkSum = FSDM_DISK_MAGIC;
  1240.         sp = (int *)diskHeaderPtr;
  1241.     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  1242.         sum ^= *sp++;
  1243.     }
  1244.         diskHeaderPtr->checkSum = sum;
  1245. }
  1246. d208 1
  1247. a208 1
  1248.  * DoNewLabel --
  1249. d210 1
  1250. a210 1
  1251.  *    Interactively gets the information for the new disk label.
  1252. d216 1
  1253. a216 1
  1254.  *    Changes diskInfoPtr.
  1255. d220 4
  1256. a223 5
  1257.     DoNewLabel(diskInfoPtr, partitionMap, numPart, streamID)
  1258.     Disk_Info        *diskInfoPtr;
  1259.     Fsdm_DiskPartition    partitionMap[];
  1260.     int            numPart;
  1261.     int            streamID;
  1262. a225 1
  1263.     char answer[80];
  1264. d229 2
  1265. d233 31
  1266. a263 32
  1267.     printf("ascii label: \"%s\", change this? (y/n) ", 
  1268.     diskInfoPtr->asciiLabel);
  1269.     if (isYes()) {
  1270.     char *tmpPtr;
  1271.     fgets(answer, 80, stdin);
  1272.     printf("New ascii label ? ");
  1273.     tmpPtr = fgets(diskInfoPtr->asciiLabel, 128,stdin);
  1274.     if (tmpPtr == NULL) {
  1275.         exit(1);
  1276.     }
  1277.     diskInfoPtr->asciiLabel[strlen(diskInfoPtr->asciiLabel)-1] = '\0';
  1278.     }
  1279.     numHeads = diskInfoPtr->numHeads;
  1280.     numSectors = diskInfoPtr->numSectors;
  1281.     printf("Sectors: summary %d, boot %d, # boot %d, domain %d, %s ",
  1282.         diskInfoPtr->summarySector, diskInfoPtr->bootSector,
  1283.         diskInfoPtr->numBootSectors, diskInfoPtr->domainSector,
  1284.         "change this? (y/n)");
  1285.     if (isYes()) {
  1286.     diskInfoPtr->summarySector = getNum("New summary sector?");
  1287.     diskInfoPtr->bootSector = getNum("New boot sector?");
  1288.     diskInfoPtr->numBootSectors = getNum("Number of boot sectors?");
  1289.     diskInfoPtr->domainSector = getNum("New domain sector?");
  1290.     }
  1291.     printf(" %d heads, change this? (y/n) ", numHeads);
  1292.     if (isYes()) {
  1293.     numHeads = getNum("New # of heads?");
  1294.     }
  1295.     printf(" %d sectors/track, change this (y/n) ", numSectors);
  1296.     if (isYes()) {
  1297.     numSectors = getNum("New # of sectors/track?");
  1298.     }
  1299. d265 1
  1300. a265 1
  1301.     diskInfoPtr->numHeads * diskInfoPtr->numSectors) {
  1302. d268 3
  1303. a270 3
  1304.     for (part=0 ; part < numPart; part++) {
  1305.         partitionMap[part].firstCylinder = 0;
  1306.         partitionMap[part].numCylinders = 0;
  1307. d273 3
  1308. a275 5
  1309.     diskInfoPtr->numHeads = numHeads;
  1310.     diskInfoPtr->numSectors = numSectors;
  1311.     for (part=0 ; part < numPart; part++) {
  1312.     first = partitionMap[part].firstCylinder;
  1313.     cyls = partitionMap[part].numCylinders;
  1314. d277 7
  1315. a283 11
  1316.     printf("\n%c: First %4d Last %4d Num %4d, change this? (y/n) ",
  1317.         'a' + part, first, last, cyls);
  1318.     if (isYes()) {
  1319.         int firstCyl = -1;
  1320.         int numCyls = -1;
  1321.  
  1322.         firstCyl = getNum("First Cyl?");
  1323.         numCyls = getNum("Num Cyls ?");
  1324.         partitionMap[part].firstCylinder = firstCyl;
  1325.         partitionMap[part].numCylinders = numCyls;
  1326.     }
  1327. d286 2
  1328. a287 12
  1329.     printf("\nNew Map\n");
  1330.     for (part=0 ; part < numPart; part++) {
  1331.     first = partitionMap[part].firstCylinder;
  1332.     cyls = partitionMap[part].numCylinders;
  1333.     last = (cyls > 0) ? (cyls + first - 1) : first;
  1334.     if (last > lastCyl) {
  1335.         lastCyl = last;
  1336.     }
  1337.     printf("%c: First %4d Last %4d Num %4d (Cylinders %7d)\n",
  1338.         'a' + part, first, last, cyls,
  1339.         partitionMap[part].numCylinders);
  1340.     }
  1341. d292 2
  1342. d296 1
  1343. a296 1
  1344.     if (!isYes()) {
  1345. d305 1
  1346. a305 1
  1347.  * ConvertSunToSprite --
  1348. d307 1
  1349. a307 3
  1350.  *    Converts a Sun label to a Sprite label. Any fields that cannot
  1351.  *    be converted directly are set to their default values.
  1352.  *    diskInfoPtr is used to get the name and the sector locations. 
  1353. d313 1
  1354. a313 1
  1355.  *    None.
  1356. d317 3
  1357. a319 6
  1358.  
  1359. void
  1360. ConvertSunToSprite(diskInfoPtr, sunLabelPtr, diskHeaderPtr)
  1361.     Disk_Info            *diskInfoPtr;
  1362.     Sun_DiskLabel        *sunLabelPtr;
  1363.     Fsdm_DiskHeader        *diskHeaderPtr;
  1364. d321 2
  1365. a322 232
  1366.     int i;
  1367.  
  1368.     /*
  1369.      * Verify the magic number and the checksum.
  1370.      */
  1371.     if (sunLabelPtr->magic != SUN_DISK_MAGIC) {
  1372.     printf("Bad magic number on disk <%x> not <%x>\n",
  1373.         sunLabelPtr->magic, SUN_DISK_MAGIC);
  1374.     }
  1375.     if (!CheckSunCheckSum(sunLabelPtr)) {
  1376.     printf("Check sum incorrect, 0x%x not 0x%x\n",
  1377.         SeeSunCheckSum(sunLabelPtr), sunLabelPtr->checkSum);
  1378.     }
  1379.     bzero(diskHeaderPtr, sizeof(*diskHeaderPtr));
  1380.     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  1381.     diskHeaderPtr->partition = 0;
  1382.     diskHeaderPtr->bootSector = diskInfoPtr->bootSector;
  1383.     diskHeaderPtr->numBootSectors = diskInfoPtr->numBootSectors;
  1384.     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  1385.     diskHeaderPtr->domainSector = diskInfoPtr->domainSector;
  1386.     diskHeaderPtr->numDomainSectors = diskInfoPtr->numDomainSectors;
  1387.     diskHeaderPtr->numSectors = sunLabelPtr->numSectors;
  1388.     diskHeaderPtr->numHeads = sunLabelPtr->numHeads;
  1389.     diskHeaderPtr->numCylinders = sunLabelPtr->numCylinders;
  1390.     diskHeaderPtr->numAltCylinders = sunLabelPtr->numAltCylinders;
  1391.     strncpy(diskHeaderPtr->asciiLabel, diskInfoPtr->asciiLabel, 128);
  1392.     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < SUN_NUM_DISK_PARTS; i++) {
  1393.     diskHeaderPtr->map[i].firstCylinder = sunLabelPtr->map[i].cylinder;
  1394.     diskHeaderPtr->map[i].numCylinders = sunLabelPtr->map[i].numBlocks /
  1395.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  1396.     }
  1397.     MakeSpriteCheckSum(diskHeaderPtr);
  1398. }
  1399.  
  1400. /*
  1401.  *----------------------------------------------------------------------
  1402.  *
  1403.  * ConvertSpriteToSun --
  1404.  *
  1405.  *    Converts a Sprite label to a Sun label. Any fields that cannot
  1406.  *    be converted directly are set to their default values.
  1407.  *
  1408.  * Results:
  1409.  *    None.
  1410.  *
  1411.  * Side effects:
  1412.  *    None.
  1413.  *
  1414.  *----------------------------------------------------------------------
  1415.  */
  1416.  
  1417. void
  1418. ConvertSpriteToSun(diskInfoPtr, diskHeaderPtr, sunLabelPtr)
  1419.     Disk_Info            *diskInfoPtr;
  1420.     Fsdm_DiskHeader        *diskHeaderPtr;
  1421.     Sun_DiskLabel        *sunLabelPtr;
  1422. {
  1423.     int i;
  1424.  
  1425.     /*
  1426.      * Verify the magic number and the checksum.
  1427.      */
  1428.     if (diskHeaderPtr->magic != FSDM_DISK_MAGIC) {
  1429.     printf("Bad magic number on disk <%x> not <%x>\n",
  1430.         diskHeaderPtr->magic, FSDM_DISK_MAGIC);
  1431.     }
  1432.     if (!CheckSpriteCheckSum(diskHeaderPtr)) {
  1433.     printf("Check sum incorrect, 0x%x not 0x%x\n",
  1434.         SeeSpriteCheckSum(diskHeaderPtr), diskHeaderPtr->checkSum);
  1435.     }
  1436.     bzero(sunLabelPtr, sizeof(*sunLabelPtr));
  1437.     sunLabelPtr->magic = SUN_DISK_MAGIC;
  1438.     sunLabelPtr->numSectors = diskHeaderPtr->numSectors;
  1439.     sunLabelPtr->numHeads = diskHeaderPtr->numHeads;
  1440.     sunLabelPtr->numCylinders = diskHeaderPtr->numCylinders;
  1441.     sunLabelPtr->numAltCylinders = diskHeaderPtr->numAltCylinders;
  1442.     sunLabelPtr->partitionID = 0;
  1443.     sunLabelPtr->bhead = 0;
  1444.     sunLabelPtr->gap1 = 65535;
  1445.     sunLabelPtr->gap2 = 65535;
  1446.     sunLabelPtr->interleave = 1;
  1447.     strncpy(sunLabelPtr->asciiLabel, diskInfoPtr->asciiLabel, 128);
  1448.     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < SUN_NUM_DISK_PARTS; i++) {
  1449.     sunLabelPtr->map[i].cylinder = diskHeaderPtr->map[i].firstCylinder;
  1450.     sunLabelPtr->map[i].numBlocks = diskHeaderPtr->map[i].numCylinders *
  1451.         diskInfoPtr->numHeads * diskInfoPtr->numSectors;
  1452.     }
  1453.     MakeSunCheckSum(sunLabelPtr);
  1454. }
  1455.  
  1456. /*
  1457.  *----------------------------------------------------------------------
  1458.  *
  1459.  * ConvertDecToSprite --
  1460.  *
  1461.  *    Converts a Dec label to a Sprite label. Any fields that cannot
  1462.  *    be converted directly are set to their default values.
  1463.  *
  1464.  * Results:
  1465.  *    None.
  1466.  *
  1467.  * Side effects:
  1468.  *    None.
  1469.  *
  1470.  *----------------------------------------------------------------------
  1471.  */
  1472.  
  1473. void
  1474. ConvertDecToSprite(diskInfoPtr, decLabelPtr, diskHeaderPtr)
  1475.     Disk_Info            *diskInfoPtr;
  1476.     Dec_DiskLabel        *decLabelPtr;
  1477.     Fsdm_DiskHeader        *diskHeaderPtr;
  1478. {
  1479.     int i;
  1480.     int cylLength = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  1481.         DEV_BYTES_PER_SECTOR;
  1482.     int totalCyls = 0;
  1483.  
  1484.     /*
  1485.      * Verify the magic number and the checksum.
  1486.      */
  1487.     if (decLabelPtr->magic != DEC_LABEL_MAGIC) {
  1488.     printf("Bad magic number on disk <%x> not <%x>\n",
  1489.         decLabelPtr->magic, DEC_LABEL_MAGIC);
  1490.     } else if (decLabelPtr->spriteMagic != FSDM_DISK_MAGIC) {
  1491.     printf("Disk has original dec label, not Sprite/dec label\n");
  1492.     }
  1493.     bzero(diskHeaderPtr, sizeof(*diskHeaderPtr));
  1494.     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  1495.     diskHeaderPtr->partition = 0;
  1496.     diskHeaderPtr->bootSector = diskInfoPtr->bootSector;
  1497.     diskHeaderPtr->numBootSectors = diskInfoPtr->numBootSectors;
  1498.     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  1499.     diskHeaderPtr->domainSector = diskInfoPtr->domainSector;
  1500.     diskHeaderPtr->numDomainSectors = diskInfoPtr->numDomainSectors;
  1501.     diskHeaderPtr->numSectors = decLabelPtr->numSectors;
  1502.     diskHeaderPtr->numHeads = decLabelPtr->numHeads;
  1503.     diskHeaderPtr->numAltCylinders = decLabelPtr->numAltCylinders;
  1504.     *diskHeaderPtr->asciiLabel = '\0';
  1505.     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < DEC_NUM_DISK_PARTS; i++) {
  1506.     if (decLabelPtr->map[i].offsetBytes % cylLength != 0) {
  1507.         printf("Warning: offset %x is not multiple of cylinder size\n",
  1508.             decLabelPtr->map[i].offsetBytes);
  1509.     }
  1510.     diskHeaderPtr->map[i].firstCylinder = decLabelPtr->map[i].numBytes/
  1511.         cylLength;
  1512.     if (decLabelPtr->map[i].numBytes % cylLength != 0) {
  1513.         printf("Warning: partition %x is not multiple of cylinder size\n",
  1514.             decLabelPtr->map[i].offsetBytes);
  1515.     }
  1516.     diskHeaderPtr->map[i].numCylinders = decLabelPtr->map[i].numBytes /
  1517.         cylLength;
  1518.     totalCyls += diskHeaderPtr->map[i].numCylinders;
  1519.     }
  1520.     diskHeaderPtr->numCylinders = totalCyls;
  1521.     MakeSpriteCheckSum(diskHeaderPtr);
  1522. }
  1523.  
  1524. /*
  1525.  *----------------------------------------------------------------------
  1526.  *
  1527.  * ConvertSpriteToDec --
  1528.  *
  1529.  *    Converts a Sprite label to a Dec label. Any fields that cannot
  1530.  *    be converted directly are set to their default values.
  1531.  *
  1532.  * Results:
  1533.  *    None.
  1534.  *
  1535.  * Side effects:
  1536.  *    None.
  1537.  *
  1538.  *----------------------------------------------------------------------
  1539.  */
  1540.  
  1541. void
  1542. ConvertSpriteToDec(diskInfoPtr, diskHeaderPtr, decLabelPtr)
  1543.     Disk_Info            *diskInfoPtr;
  1544.     Fsdm_DiskHeader        *diskHeaderPtr;
  1545.     Dec_DiskLabel        *decLabelPtr;
  1546. {
  1547.     int i;
  1548.     int cylLength = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  1549.         DEV_BYTES_PER_SECTOR;
  1550.  
  1551.     /*
  1552.      * Verify the magic number and the checksum.
  1553.      */
  1554.     if (diskHeaderPtr->magic != FSDM_DISK_MAGIC) {
  1555.     printf("Bad magic number on disk <%x> not <%x>\n",
  1556.         diskHeaderPtr->magic, FSDM_DISK_MAGIC);
  1557.     }
  1558.     bzero(decLabelPtr, sizeof(*decLabelPtr));
  1559.     decLabelPtr->magic = DEC_LABEL_MAGIC;
  1560.     decLabelPtr->isPartitioned = 1;
  1561.     decLabelPtr->numHeads = diskHeaderPtr->numHeads;
  1562.     decLabelPtr->numSectors = diskHeaderPtr->numSectors;
  1563.     decLabelPtr->domainSector = diskHeaderPtr->domainSector;
  1564.     decLabelPtr->numDomainSectors = diskHeaderPtr->numDomainSectors;
  1565.     decLabelPtr->numCylinders = diskHeaderPtr->numCylinders;
  1566.     decLabelPtr->numAltCylinders = diskHeaderPtr->numAltCylinders;
  1567.     decLabelPtr->bootSector = DEC_BOOT_SECTOR;
  1568.     decLabelPtr->numBootSectors = diskHeaderPtr->numBootSectors;
  1569.     decLabelPtr->summarySector = diskHeaderPtr->summarySector;
  1570.     decLabelPtr->domainSector = diskHeaderPtr->domainSector;
  1571.     decLabelPtr->numDomainSectors = diskHeaderPtr->numDomainSectors;
  1572.     decLabelPtr->spriteMagic = FSDM_DISK_MAGIC;
  1573.     strncpy(decLabelPtr->asciiLabel, diskInfoPtr->asciiLabel, 128);
  1574.     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < DEC_NUM_DISK_PARTS; i++) {
  1575.     decLabelPtr->map[i].numBytes = diskHeaderPtr->map[i].numCylinders *
  1576.             cylLength;
  1577.     decLabelPtr->map[i].offsetBytes = diskHeaderPtr->map[i].firstCylinder *
  1578.         cylLength;
  1579.     }
  1580. }
  1581.  
  1582.  
  1583. /*
  1584.  *----------------------------------------------------------------------
  1585.  *
  1586.  * DoDecLabel --
  1587.  *
  1588.  *    Sets up a Dec label.
  1589.  *
  1590.  * Results:
  1591.  *    None.
  1592.  *
  1593.  * Side effects:
  1594.  *    None.
  1595.  *
  1596.  *----------------------------------------------------------------------
  1597.  */
  1598. d324 2
  1599. a325 56
  1600. ReturnStatus
  1601. DoDecLabel(diskInfoPtr, streamID, decLabelPtr)
  1602.     Disk_Info            *diskInfoPtr;
  1603.     int                streamID;
  1604.     Dec_DiskLabel         *decLabelPtr;
  1605. {
  1606.     int             part;
  1607.     ReturnStatus         status = SUCCESS;
  1608.     int                cyls;
  1609.     int                first;
  1610.     int                last;
  1611.     int                cylLength;
  1612.     Fsdm_DiskPartition        partitionMap[DEC_NUM_DISK_PARTS];
  1613.  
  1614.     printInfo("DEC", diskInfoPtr);
  1615.  
  1616.     /*
  1617.      * Verify the magic number and the checksum.
  1618.      */
  1619.     if (decLabelPtr->magic != DEC_LABEL_MAGIC) {
  1620.     printf("Bad magic number on disk <%x> not <%x>\n",
  1621.         decLabelPtr->magic, DEC_LABEL_MAGIC);
  1622.     }
  1623.     cylLength = decLabelPtr->numHeads * decLabelPtr->numSectors *
  1624.         DEV_BYTES_PER_SECTOR;
  1625.     for (part=0 ; part < DEC_NUM_DISK_PARTS; part++) {
  1626.     first = decLabelPtr->map[part].offsetBytes / cylLength;;
  1627.     cyls = decLabelPtr->map[part].numBytes / cylLength;
  1628.     last = (cyls > 0) ? (cyls + first - 1) : first;
  1629.     printf("%c: First %4d Last %4d Num %4d (Bytes %7d)\n",
  1630.         'a' + part, first, last, cyls,
  1631.         decLabelPtr->map[part].numBytes);
  1632.     partitionMap[part].firstCylinder = first;
  1633.     partitionMap[part].numCylinders = cyls;
  1634.     }
  1635.     if (!writeLabel) {
  1636.     return(SUCCESS);
  1637.     }
  1638.     DoNewLabel(diskInfoPtr,partitionMap,DEC_NUM_DISK_PARTS, streamID);
  1639.     decLabelPtr->numHeads = diskInfoPtr->numHeads;
  1640.     decLabelPtr->numSectors = diskInfoPtr->numSectors;
  1641.     decLabelPtr->summarySector = diskInfoPtr->summarySector;
  1642.     decLabelPtr->bootSector = diskInfoPtr->bootSector;
  1643.     decLabelPtr->numBootSectors = diskInfoPtr->numBootSectors;
  1644.     decLabelPtr->domainSector = diskInfoPtr->domainSector;
  1645.     decLabelPtr->version = DEC_LABEL_VERSION;
  1646.     decLabelPtr->magic = DEC_LABEL_MAGIC;
  1647.     decLabelPtr->spriteMagic = FSDM_DISK_MAGIC;
  1648.     strcpy(decLabelPtr->asciiLabel, diskInfoPtr->asciiLabel);
  1649.     cylLength = decLabelPtr->numHeads * decLabelPtr->numSectors *
  1650.         DEV_BYTES_PER_SECTOR;
  1651.     for (part=0 ; part < DEC_NUM_DISK_PARTS; part++) {
  1652.     decLabelPtr->map[part].offsetBytes = partitionMap[part].firstCylinder *
  1653.         cylLength;
  1654.     decLabelPtr->map[part].numBytes = partitionMap[part].numCylinders *
  1655.         cylLength;
  1656. d327 7
  1657. a333 98
  1658.     printf("Writing new dec label\n");
  1659.     status = Disk_SectorWrite(streamID, DEC_LABEL_SECTOR, 1, decLabelPtr);
  1660.     return status;
  1661. }
  1662.  
  1663. /*
  1664.  *----------------------------------------------------------------------
  1665.  *
  1666.  * EraseOldLabel --
  1667.  *
  1668.  *    Zero out the block containing the old label.
  1669.  *
  1670.  * Results:
  1671.  *    Status.
  1672.  *
  1673.  * Side effects:
  1674.  *    None.
  1675.  *
  1676.  *----------------------------------------------------------------------
  1677.  */
  1678.  
  1679. ReturnStatus
  1680. EraseOldLabel(streamID, sector)
  1681. int streamID;
  1682. int sector;
  1683. {
  1684.     char buffer[DEV_BYTES_PER_SECTOR];
  1685.     bzero(buffer, DEV_BYTES_PER_SECTOR);
  1686.     printf("Erasing label at sector %d\n",sector);
  1687.     return Disk_SectorWrite(streamID, sector, 1, buffer);
  1688. }
  1689.  
  1690. /*
  1691.  *----------------------------------------------------------------------
  1692.  *
  1693.  * printInfo --
  1694.  *
  1695.  *    Print out info in the diskInfoPtr;
  1696.  *
  1697.  * Results:
  1698.  *    None.
  1699.  *
  1700.  * Side effects:
  1701.  *    None.
  1702.  *
  1703.  *----------------------------------------------------------------------
  1704.  */
  1705. printInfo(type, diskInfoPtr)
  1706. char                *type;
  1707. Disk_Info            *diskInfoPtr;
  1708. {
  1709.     printf("%s LABEL <%s>\n", type, diskInfoPtr->asciiLabel);
  1710.     printf(" %d heads %d sectors/track\n",
  1711.     diskInfoPtr->numHeads, diskInfoPtr->numSectors);
  1712.     printf("Boot sector = %x\n", diskInfoPtr->bootSector);
  1713.     printf("Number of boot sectors = %x\n", diskInfoPtr->numBootSectors);
  1714.     printf("Summary sector = %x\n", diskInfoPtr->summarySector);
  1715.     printf("Domain sector = %x\n", diskInfoPtr->domainSector);
  1716.     printf("Number of domain sectors = %x\n", diskInfoPtr->numDomainSectors);
  1717. }
  1718.  
  1719. /*
  1720.  *----------------------------------------------------------------------
  1721.  *
  1722.  * getNum --
  1723.  *
  1724.  *    Get a number interactively.
  1725.  *
  1726.  * Results:
  1727.  *    Number.
  1728.  *
  1729.  * Side effects:
  1730.  *    None.
  1731.  *
  1732.  *----------------------------------------------------------------------
  1733.  */
  1734. int
  1735. getNum(string)
  1736. char    *string;
  1737. {
  1738.     int n, val;
  1739.     char answer[80];
  1740.     do {
  1741.     printf("%s ",string);
  1742.     n = scanf("%d", &val);
  1743.     if (n == EOF) {
  1744.         exit(1);
  1745.     }
  1746.     if (n == 0) {
  1747.         /*
  1748.          * Skip the trashy line
  1749.          */
  1750.         fgets(answer, sizeof(answer), stdin);
  1751.     }
  1752.     } while (n<1);
  1753.     return val;
  1754. }
  1755.  
  1756. d337 1
  1757. a337 1
  1758.  * isYes --
  1759. d349 2
  1760. a350 2
  1761. int
  1762. isYes()
  1763. @
  1764.  
  1765.  
  1766. 1.6
  1767. log
  1768. @handles disks without a label, you can edit the ascii string, and
  1769. answering "n" to not commit the label sends you back to re-edit the 
  1770. label
  1771. @
  1772. text
  1773. @d4 1
  1774. a4 1
  1775.  *    Read and possible change the disk label.
  1776. d11 1
  1777. a11 1
  1778. static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.5 90/01/11 15:11:41 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  1779. d28 1
  1780. d30 1
  1781. d33 2
  1782. a34 1
  1783.     {OPT_DOC,"",(Address)NIL, "labeldisk [-w] [-sun] [-sprite] rawDevice"},
  1784. d39 2
  1785. d43 2
  1786. d51 5
  1787. a55 2
  1788. extern void    ConvertSunToSprite();
  1789. extern void    ConvertSpriteToSun();
  1790. d60 1
  1791. d91 3
  1792. d99 3
  1793. a101 2
  1794.     if (writeSun && writeSprite) {
  1795.     fprintf(stderr, "Can't specify both -sun and -sprite.\n");
  1796. d110 1
  1797. a110 1
  1798.     if (LabelDisk(streamID) < 0) {
  1799. d136 1
  1800. d140 1
  1801. d145 3
  1802. a147 2
  1803.     static char    *labelName[2] = {"Sun", "Sprite"};
  1804.     static char buffer[1024];
  1805. d152 2
  1806. d159 2
  1807. d162 1
  1808. a162 1
  1809.     if (diskInfoPtr != (Disk_Info *)0) {
  1810. a165 1
  1811.         diskHeaderPtr = (Fsdm_DiskHeader *) buffer;
  1812. d167 1
  1813. a170 1
  1814.         sunLabelPtr = (Sun_DiskLabel *) buffer;
  1815. d172 8
  1816. a179 2
  1817.         fprintf(stderr, "Disk label is neither Sun nor Sprite.\n");
  1818.         return(FAILURE);
  1819. d184 3
  1820. a186 1
  1821.     printf("The disk does not have a label.\n");
  1822. d191 1
  1823. a191 1
  1824.         printf("You must specify either the -sun or -sprite option.\n");
  1825. d196 13
  1826. a208 6
  1827.     bzero(&diskHeader, sizeof(Fsdm_DiskHeader));
  1828.     diskInfoPtr = &diskInfo;
  1829.     diskInfoPtr->bootSector = 1;
  1830.     diskInfoPtr->numBootSectors = 15;
  1831.     diskInfoPtr->summarySector = 17;
  1832.     diskInfoPtr->domainSector = 18;
  1833. d211 1
  1834. a211 2
  1835.     sunLabelPtr->magic = SUN_DISK_MAGIC;
  1836.     MakeSunCheckSum(sunLabelPtr);
  1837. a212 2
  1838.     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  1839.     MakeSpriteCheckSum(diskHeaderPtr);
  1840. d218 5
  1841. d233 3
  1842. d238 4
  1843. a241 1
  1844.     } else {
  1845. d243 2
  1846. d247 3
  1847. d251 3
  1848. a253 1
  1849.     return DoSunLabel(diskInfoPtr, streamID, sunLabelPtr);
  1850. d255 12
  1851. a266 3
  1852.     return DoSpriteLabel(diskInfoPtr, streamID, diskHeaderPtr);
  1853.     }
  1854. }
  1855. d291 1
  1856. a291 3
  1857.     int             totalCyls, part;
  1858.     int             n;
  1859.     char             answer[80];
  1860. d296 1
  1861. a296 11
  1862.     int                numHeads;
  1863.     int                numSectors;
  1864.     int                numCyls;
  1865.     int                lastSector;
  1866.     int                totalSectors;
  1867.     int                lastCyl;
  1868.     char            buffer[DEV_BYTES_PER_SECTOR];
  1869.  
  1870.     for (totalSectors = 0, part = 0; part < SUN_NUM_DISK_PARTS; part++) {
  1871.     totalSectors += sunLabelPtr->map[part].numBlocks;
  1872.     }
  1873. d298 1
  1874. a298 3
  1875.     printf("SUN LABEL <%s>\n", diskInfoPtr->asciiLabel);
  1876.     printf(" %d heads %d sectors/track\n",
  1877.     diskInfoPtr->numHeads, diskInfoPtr->numSectors);
  1878. d313 14
  1879. a326 6
  1880.     cyls = sunLabelPtr->map[part].numBlocks /
  1881.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  1882.     last = (cyls > 0) ? (cyls + first - 1) : first;
  1883.     printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  1884.         'a' + part, first, last, cyls,
  1885.         sunLabelPtr->map[part].numBlocks);
  1886. d331 4
  1887. a334 68
  1888. editLabel:
  1889.     printf("ascii label: \"%s\", change this? (y/n) ", 
  1890.     sunLabelPtr->asciiLabel);
  1891.     n = scanf("%s", answer);
  1892.     if (n == EOF) {
  1893.     exit(1);
  1894.     }
  1895.     if (strcmp(answer, "y") == 0) {
  1896.     char *tmpPtr;
  1897.     fgets(answer, 80, stdin);
  1898.     printf("New ascii label ? ");
  1899.     tmpPtr = fgets(sunLabelPtr->asciiLabel, 128,stdin);
  1900.     if (tmpPtr == NULL) {
  1901.         exit(1);
  1902.     }
  1903.     sunLabelPtr->asciiLabel[strlen(sunLabelPtr->asciiLabel)-1] = '\0';
  1904.     }
  1905.     numHeads = diskInfoPtr->numHeads;
  1906.     numSectors = diskInfoPtr->numSectors;
  1907.     printf(" %d heads, change this? (y/n) ", numHeads);
  1908.     n = scanf("%s", answer);
  1909.     if (n == EOF) {
  1910.     exit(1);
  1911.     }
  1912.     if (strcmp(answer, "y") == 0) {
  1913.     printf("New # of heads ? ");
  1914.     n = scanf("%d", &numHeads);
  1915.     if (n == EOF) {
  1916.         exit(1);
  1917.     }
  1918.     if (n == 0) {
  1919.         /*
  1920.          * Skip the trashy line
  1921.          */
  1922.         fgets(answer, sizeof(answer), streamID);
  1923.     }
  1924.     }
  1925.     printf(" %d sectors/track, change this (y/n) ", numSectors);
  1926.     n = scanf("%s", answer);
  1927.     if (n == EOF) {
  1928.     exit(1);
  1929.     }
  1930.     if (strcmp(answer, "y") == 0) {
  1931.     printf("New # of sectors/track ? ");
  1932.     n = scanf("%d", &numSectors);
  1933.     if (n == EOF) {
  1934.         exit(1);
  1935.     }
  1936.     if (n == 0) {
  1937.         /*
  1938.          * Skip the trashy line
  1939.          */
  1940.         fgets(answer, sizeof(answer), streamID);
  1941.     }
  1942.     }
  1943.     if (numHeads * numSectors != 
  1944.     diskInfoPtr->numHeads * diskInfoPtr->numSectors) {
  1945.     printf(
  1946.     "The size of a cylinder changed so I have to zero the partition map.\n");
  1947.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  1948.         sunLabelPtr->map[part].cylinder = 0;
  1949.         sunLabelPtr->map[part].numBlocks = 0;
  1950.     }
  1951.     }
  1952.     diskInfoPtr->numHeads = numHeads;
  1953.     diskInfoPtr->numSectors = numSectors;
  1954.     sunLabelPtr->numHeads = numHeads;
  1955.     sunLabelPtr->numSectors = numSectors;
  1956. d336 3
  1957. a338 44
  1958.     first = sunLabelPtr->map[part].cylinder;
  1959.     cyls = sunLabelPtr->map[part].numBlocks /
  1960.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  1961.     last = (cyls > 0) ? (cyls + first - 1) : first;
  1962.     printf("\n%c: First %4d Last %4d Num %4d, change this? (y/n) ",
  1963.         'a' + part, first, last, cyls);
  1964.     n = scanf("%s", answer);
  1965.     if (n == EOF) {
  1966.         exit(1);
  1967.     }
  1968.     if (strcmp(answer, "y") == 0) {
  1969.         int firstCyl = -1;
  1970.         int numCyls = -1;
  1971.  
  1972.         do {
  1973.         printf("First Cyl ? ");
  1974.         n = scanf("%d", &firstCyl);
  1975.         if (n == EOF) {
  1976.             exit(1);
  1977.         }
  1978.         if (n == 0) {
  1979.             /*
  1980.              * Skip the trashy line
  1981.              */
  1982.             fgets(answer, sizeof(answer), streamID);
  1983.         }
  1984.         } while (n < 1);
  1985.         do {
  1986.         printf("Num Cyls ? ");
  1987.         n = scanf("%d", &numCyls);
  1988.         if (n == EOF) {
  1989.             exit(1);
  1990.         }
  1991.         if (n == 0) {
  1992.             /*
  1993.              * Skip the trashy line
  1994.              */
  1995.             fgets(answer, sizeof(answer), streamID);
  1996.         }
  1997.         } while (n < 1);
  1998.         sunLabelPtr->map[part].cylinder = firstCyl;
  1999.         sunLabelPtr->map[part].numBlocks = numCyls * 
  2000.                 diskInfoPtr->numHeads * diskInfoPtr->numSectors;
  2001.     }
  2002. d340 1
  2003. d342 3
  2004. a344 33
  2005.     lastCyl = 0;
  2006.     printf("\nNew Map\n");
  2007.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  2008.     first = sunLabelPtr->map[part].cylinder;
  2009.     cyls = sunLabelPtr->map[part].numBlocks /
  2010.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  2011.     last = (cyls > 0) ? (cyls + first - 1) : first;
  2012.     if (last > lastCyl) {
  2013.         lastCyl = last;
  2014.     }
  2015.     printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  2016.         'a' + part, first, last, cyls,
  2017.         sunLabelPtr->map[part].numBlocks);
  2018.     }
  2019.     lastSector = (lastCyl + 1) * numHeads * numSectors - 1;
  2020.     status = Disk_SectorRead(streamID, lastSector, 1, buffer);
  2021.     if (status != 0) {
  2022.     printf("I couldn't read the last sector (sector %d)!!!\n", lastSector);
  2023.     }
  2024.     printf("\nCommit new label? (y/n) ");
  2025.     n = scanf("%s", answer);
  2026.     if (n == EOF) {
  2027.     exit(1);
  2028.     }
  2029.     if (strcmp(answer, "y") == 0) {
  2030.     printf("Writing new label\n");
  2031.     status = Disk_SectorWrite(streamID, 0, 1, sunLabelPtr);
  2032.     } else {
  2033.     printf("Try again\n");
  2034.     goto editLabel;
  2035.     }
  2036.  
  2037.     return(status);
  2038. d408 1
  2039. a408 1
  2040.     int             totalCyls, part;
  2041. a409 1
  2042.     char             answer[80];
  2043. a414 11
  2044.     int                numHeads;
  2045.     int                numSectors;
  2046.     int                numCyls;
  2047.     int                totalSectors;
  2048.     int                lastSector;
  2049.     int                lastCyl;
  2050.     char            buffer[DEV_BYTES_PER_SECTOR];
  2051.  
  2052.     for (totalCyls = 0, part = 0; part < FSDM_NUM_DISK_PARTS; part++) {
  2053.     totalCyls += diskHeaderPtr->map[part].numCylinders;
  2054.     }
  2055. d416 1
  2056. a416 3
  2057.     printf("SPRITE LABEL <%s>\n", diskInfoPtr->asciiLabel);
  2058.     printf(" %d heads %d sectors/track\n",
  2059.     diskInfoPtr->numHeads, diskInfoPtr->numSectors);
  2060. d441 6
  2061. a446 1
  2062. editLabel:
  2063. a448 1
  2064.     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  2065. d450 82
  2066. a531 1
  2067.     diskHeaderPtr->numDomainSectors = diskInfoPtr->numDomainSectors;
  2068. d533 2
  2069. a534 6
  2070.     diskHeaderPtr->asciiLabel);
  2071.     n = scanf("%s", answer);
  2072.     if (n == EOF) {
  2073.     exit(1);
  2074.     }
  2075.     if (strcmp(answer, "y") == 0) {
  2076. d537 2
  2077. a538 2
  2078.     printf(" New ascii label ? ");
  2079.     tmpPtr = fgets(diskHeaderPtr->asciiLabel, 128,stdin);
  2080. d542 1
  2081. a542 1
  2082.     diskHeaderPtr->asciiLabel[strlen(diskHeaderPtr->asciiLabel)-1] = '\0';
  2083. d546 10
  2084. a555 2
  2085.     numCyls = totalCyls;
  2086.     totalSectors = numCyls * numHeads * numSectors;
  2087. d557 2
  2088. a558 16
  2089.     n = scanf("%s", answer);
  2090.     if (n == EOF) {
  2091.     exit(1);
  2092.     }
  2093.     if (strcmp(answer, "y") == 0) {
  2094.     printf("New # of heads ? ");
  2095.     n = scanf("%d", &numHeads);
  2096.     if (n == EOF) {
  2097.         exit(1);
  2098.     }
  2099.     if (n == 0) {
  2100.         /*
  2101.          * Skip the trashy line
  2102.          */
  2103.         fgets(answer, sizeof(answer), streamID);
  2104.     }
  2105. d561 2
  2106. a562 16
  2107.     n = scanf("%s", answer);
  2108.     if (n == EOF) {
  2109.     exit(1);
  2110.     }
  2111.     if (strcmp(answer, "y") == 0) {
  2112.     printf("New # of sectors/track ? ");
  2113.     n = scanf("%d", &numSectors);
  2114.     if (n == EOF) {
  2115.         exit(1);
  2116.     }
  2117.     if (n == 0) {
  2118.         /*
  2119.          * Skip the trashy line
  2120.          */
  2121.         fgets(answer, sizeof(answer), streamID);
  2122.     }
  2123. d568 3
  2124. a570 3
  2125.     for (part=0 ; part < FSDM_NUM_DISK_PARTS; part++) {
  2126.         diskHeaderPtr->map[part].firstCylinder = 0;
  2127.         diskHeaderPtr->map[part].numCylinders = 0;
  2128. d575 3
  2129. a577 5
  2130.     diskHeaderPtr->numHeads = numHeads;
  2131.     diskHeaderPtr->numSectors = numSectors;
  2132.     for (part=0 ; part < FSDM_NUM_DISK_PARTS; part++) {
  2133.     first = diskHeaderPtr->map[part].firstCylinder;
  2134.     cyls = diskHeaderPtr->map[part].numCylinders;
  2135. d581 1
  2136. a581 5
  2137.     n = scanf("%s", answer);
  2138.     if (n == EOF) {
  2139.         exit(1);
  2140.     }
  2141.     if (strcmp(answer, "y") == 0) {
  2142. d585 4
  2143. a588 28
  2144.         do {
  2145.         printf("First Cyl ? ");
  2146.         n = scanf("%d", &firstCyl);
  2147.         if (n == EOF) {
  2148.             exit(1);
  2149.         }
  2150.         if (n == 0) {
  2151.             /*
  2152.              * Skip the trashy line
  2153.              */
  2154.             fgets(answer, sizeof(answer), streamID);
  2155.         }
  2156.         } while (n < 1);
  2157.         do {
  2158.         printf("Num Cyls ? ");
  2159.         n = scanf("%d", &numCyls);
  2160.         if (n == EOF) {
  2161.             exit(1);
  2162.         }
  2163.         if (n == 0) {
  2164.             /*
  2165.              * Skip the trashy line
  2166.              */
  2167.             fgets(answer, sizeof(answer), streamID);
  2168.         }
  2169.         } while (n < 1);
  2170.         diskHeaderPtr->map[part].firstCylinder = firstCyl;
  2171.         diskHeaderPtr->map[part].numCylinders = numCyls;
  2172. a590 5
  2173.     MakeSpriteCheckSum(diskHeaderPtr);
  2174.     if (!CheckSpriteCheckSum(diskHeaderPtr)) {
  2175.     printf("Check sum incorrect, 0x%x not 0x%x\n",
  2176.         SeeSpriteCheckSum(diskHeaderPtr), FSDM_DISK_MAGIC);
  2177.     }
  2178. d593 3
  2179. a595 3
  2180.     for (part=0 ; part < FSDM_NUM_DISK_PARTS; part++) {
  2181.     first = diskHeaderPtr->map[part].firstCylinder;
  2182.     cyls = diskHeaderPtr->map[part].numCylinders;
  2183. d600 3
  2184. a602 4
  2185.     blocks = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  2186.         diskHeaderPtr->map[part].numCylinders;
  2187.     printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  2188.         'a' + part, first, last, cyls, blocks);
  2189. d610 1
  2190. a610 8
  2191.     n = scanf("%s", answer);
  2192.     if (n == EOF) {
  2193.     exit(1);
  2194.     }
  2195.     if (strcmp(answer, "y") == 0) {
  2196.     printf("Writing new label\n");
  2197.     status = Disk_SectorWrite(streamID, 0, 1, diskHeaderPtr);
  2198.     } else {
  2199. a613 43
  2200.     return(status);
  2201. }
  2202.  
  2203. unsigned int
  2204. SeeSpriteCheckSum(diskHeaderPtr)
  2205.     Fsdm_DiskHeader *diskHeaderPtr;
  2206. {
  2207.         int *sp, sum = 0;
  2208.     int i;
  2209.  
  2210.         sp = (int *)diskHeaderPtr;
  2211.     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  2212.         sum ^= *sp++;
  2213.     }
  2214.         return (sum);
  2215. }
  2216.  
  2217. int
  2218. CheckSpriteCheckSum(diskHeaderPtr)
  2219.     Fsdm_DiskHeader *diskHeaderPtr;
  2220. {
  2221.         int *sp, sum = 0;
  2222.     int i;
  2223.  
  2224.         sp = (int *)diskHeaderPtr;
  2225.     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  2226.         sum ^= *sp++;
  2227.     }
  2228.         return (sum == FSDM_DISK_MAGIC ? 1 : 0);
  2229. }
  2230.  
  2231. MakeSpriteCheckSum(diskHeaderPtr)
  2232.     Fsdm_DiskHeader *diskHeaderPtr;
  2233. {
  2234.         int *sp, sum = 0;
  2235.     int i;
  2236.  
  2237.     diskHeaderPtr->checkSum = FSDM_DISK_MAGIC;
  2238.         sp = (int *)diskHeaderPtr;
  2239.     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  2240.         sum ^= *sp++;
  2241.     }
  2242.         diskHeaderPtr->checkSum = sum;
  2243. d623 1
  2244. d730 328
  2245. @
  2246.  
  2247.  
  2248. 1.5
  2249. log
  2250. @now you can change #sectors/track, #heads, etc
  2251. @
  2252. text
  2253. @d11 1
  2254. a11 1
  2255. static char rcsid[] = "$Header: /a/newcmds/labeldisk/RCS/labeldisk.c,v 1.4 89/08/01 23:32:23 jhh Exp $ SPRITE (Berkeley)";
  2256. d31 1
  2257. a31 2
  2258.     {OPT_STRING, "d", (Address)&deviceName,
  2259.     "Required (if no -u): Name of raw disk device, eg. \"/dev/rsd0\""},
  2260. d47 1
  2261. d75 1
  2262. a75 2
  2263.  
  2264.     if (deviceName == (char *)0) {
  2265. d79 1
  2266. d122 3
  2267. d140 15
  2268. a154 7
  2269.     if (diskInfoPtr == (Disk_Info *)0) {
  2270.     return(FAILURE);
  2271.     }
  2272.     sunLabelPtr = Disk_ReadSunLabel(streamID);
  2273.     if (sunLabelPtr != (Sun_DiskLabel *)0) {
  2274.     inLabel = SUNLABEL;
  2275.     diskHeaderPtr = (Fsdm_DiskHeader *) buffer;
  2276. d156 7
  2277. a162 6
  2278.     diskHeaderPtr = Disk_ReadDiskHeader(streamID);
  2279.     if (diskHeaderPtr != (Fsdm_DiskHeader *) 0) {
  2280.         inLabel = SPRITELABEL;
  2281.         sunLabelPtr = (Sun_DiskLabel *) buffer;
  2282.     } else {
  2283.         fprintf(stderr, "Disk label is neither Sun nor Sprite.\n");
  2284. d165 15
  2285. d181 1
  2286. a181 1
  2287.     if (outLabel == -1) {
  2288. d184 1
  2289. a184 1
  2290.     if (inLabel != outLabel) {
  2291. d277 17
  2292. d420 2
  2293. a421 1
  2294.     printf("Bailing out\n");
  2295. d535 22
  2296. d687 2
  2297. a688 1
  2298.     printf("Bailing out\n");
  2299. a689 1
  2300.  
  2301. @
  2302.  
  2303.  
  2304. 1.4
  2305. log
  2306. @fixed a stupid bug in computing sun checksums
  2307. @
  2308. text
  2309. @d11 1
  2310. a11 1
  2311. static char rcsid[] = "$Header: /a/newcmds/labeldisk/RCS/labeldisk.c,v 1.3 89/08/01 23:27:56 jhh Exp $ SPRITE (Berkeley)";
  2312. a70 1
  2313.     ReturnStatus status;    /* status of system calls */
  2314. d121 1
  2315. a121 1
  2316.     FsDiskHeader        *diskHeaderPtr;
  2317. d143 1
  2318. a143 1
  2319.     diskHeaderPtr = (FsDiskHeader *) buffer;
  2320. d146 1
  2321. a146 1
  2322.     if (diskHeaderPtr != (FsDiskHeader *) 0) {
  2323. d211 7
  2324. d219 2
  2325. a220 3
  2326.     for (totalCyls = 0, part = 0; part < SUN_NUM_DISK_PARTS; part++) {
  2327.     totalCyls += sunLabelPtr->map[part].numBlocks /
  2328.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  2329. a226 9
  2330.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  2331.     first = sunLabelPtr->map[part].cylinder;
  2332.     cyls = sunLabelPtr->map[part].numBlocks /
  2333.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  2334.     last = (cyls > 0) ? (cyls + first - 1) : first;
  2335.     printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  2336.         'a' + part, first, last, cyls,
  2337.         sunLabelPtr->map[part].numBlocks);
  2338.     }
  2339. d238 9
  2340. d250 51
  2341. d348 1
  2342. d355 3
  2343. d362 5
  2344. d441 1
  2345. a441 1
  2346.     FsDiskHeader    *diskHeaderPtr;
  2347. d451 7
  2348. d459 1
  2349. a459 1
  2350.     for (totalCyls = 0, part = 0; part < FS_NUM_DISK_PARTS; part++) {
  2351. d467 11
  2352. d487 24
  2353. a510 6
  2354.     /*
  2355.      * Verify the magic number and the checksum.
  2356.      */
  2357.     if (diskHeaderPtr->magic != FS_DISK_MAGIC) {
  2358.     printf("Bad magic number on disk <%x> not <%x>\n",
  2359.         diskHeaderPtr->magic, FS_DISK_MAGIC);
  2360. d512 4
  2361. a515 3
  2362.     if (!CheckSpriteCheckSum(diskHeaderPtr)) {
  2363.     printf("Check sum incorrect, 0x%x not 0x%x\n",
  2364.         SeeSpriteCheckSum(diskHeaderPtr), FS_DISK_MAGIC);
  2365. d517 12
  2366. a528 2
  2367.     if (!writeLabel) {
  2368.     return(SUCCESS);
  2369. d530 14
  2370. a543 1
  2371.     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  2372. d590 1
  2373. a590 1
  2374.         SeeSpriteCheckSum(diskHeaderPtr), FS_DISK_MAGIC);
  2375. d592 1
  2376. d594 1
  2377. a594 1
  2378.     for (part=0 ; part < FS_NUM_DISK_PARTS; part++) {
  2379. d598 3
  2380. d606 5
  2381. d628 1
  2382. a628 1
  2383.     FsDiskHeader *diskHeaderPtr;
  2384. d642 1
  2385. a642 1
  2386.     FsDiskHeader *diskHeaderPtr;
  2387. d651 1
  2388. a651 1
  2389.         return (sum == FS_DISK_MAGIC ? 1 : 0);
  2390. d655 1
  2391. a655 1
  2392.     FsDiskHeader *diskHeaderPtr;
  2393. d660 1
  2394. a660 1
  2395.     diskHeaderPtr->checkSum = FS_DISK_MAGIC;
  2396. d689 1
  2397. a689 1
  2398.     FsDiskHeader        *diskHeaderPtr;
  2399. d705 1
  2400. a705 1
  2401.     diskHeaderPtr->magic = FS_DISK_MAGIC;
  2402. d717 1
  2403. a717 1
  2404.     for (i = 0; i < FS_NUM_DISK_PARTS && i < SUN_NUM_DISK_PARTS; i++) {
  2405. d745 1
  2406. a745 1
  2407.     FsDiskHeader        *diskHeaderPtr;
  2408. d753 1
  2409. a753 1
  2410.     if (diskHeaderPtr->magic != FS_DISK_MAGIC) {
  2411. d755 1
  2412. a755 1
  2413.         diskHeaderPtr->magic, FS_DISK_MAGIC);
  2414. d773 1
  2415. a773 1
  2416.     for (i = 0; i < FS_NUM_DISK_PARTS && i < SUN_NUM_DISK_PARTS; i++) {
  2417. @
  2418.  
  2419.  
  2420. 1.3
  2421. log
  2422. @Now does Sprite labels
  2423. @
  2424. text
  2425. @d11 1
  2426. a11 1
  2427. static char rcsid[] = "$Header: /a/newcmds/labeldisk/RCS/labeldisk.c,v 1.2 89/06/19 14:34:44 jhh Exp $ SPRITE (Berkeley)";
  2428. d335 1
  2429. a335 1
  2430.         short count = DEV_BYTES_PER_SECTOR/sizeof(short) -1;
  2431. @
  2432.  
  2433.  
  2434. 1.2
  2435. log
  2436. @fixed bug calling Opt_PrintUsage
  2437. @
  2438. text
  2439. @d11 1
  2440. a11 1
  2441. static char rcsid[] = "$Header: /a/newcmds/labeldisk/RCS/labeldisk.c,v 1.1 88/12/05 10:02:06 brent Exp $ SPRITE (Berkeley)";
  2442. d27 2
  2443. d35 4
  2444. d42 2
  2445. a43 1
  2446. short SeeCheckSum();
  2447. d45 6
  2448. d86 5
  2449. d94 1
  2450. a94 1
  2451.     exit(status);
  2452. d96 1
  2453. a96 1
  2454.     if (LabelDisk(streamID, writeLabel) < 0) {
  2455. d117 1
  2456. a117 1
  2457. LabelDisk(streamID, writeLabel)
  2458. a118 1
  2459.     Boolean writeLabel;            /* If TRUE then write new label */
  2460. d120 9
  2461. a128 8
  2462.     ReturnStatus status = SUCCESS;
  2463.     Disk_Info *diskInfoPtr;
  2464.     Sun_DiskLabel *sunLabelPtr;
  2465.     int totalCyls, part;
  2466.     int i, n;
  2467.     char answer[80];
  2468.     register unsigned short checkSum;
  2469.     register unsigned short *shortPtr;
  2470. d130 7
  2471. a136 1
  2472.  
  2473. d142 37
  2474. a178 3
  2475.     if (sunLabelPtr == (Sun_DiskLabel *)0) {
  2476.     fprintf(stderr, "I only do Sun labels\n");
  2477.     return(FAILURE);
  2478. d180 18
  2479. d199 14
  2480. d223 6
  2481. a228 5
  2482.     printf("%c: First Cyl %4d Num Cyl %4d (Blocks %5d)\n",
  2483.         'a' + part,
  2484.         sunLabelPtr->map[part].cylinder,
  2485.         sunLabelPtr->map[part].numBlocks /
  2486.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors),
  2487. d238 1
  2488. a238 1
  2489.     if (!CheckCheckSum(sunLabelPtr)) {
  2490. d240 1
  2491. a240 1
  2492.         SeeCheckSum(sunLabelPtr), sunLabelPtr->checkSum);
  2493. d246 6
  2494. a251 5
  2495.     printf("\n%c: First Cyl %4d Num Cyl %4d, change this? (y/n) ",
  2496.         'a' + part,
  2497.         sunLabelPtr->map[part].cylinder,
  2498.         sunLabelPtr->map[part].numBlocks /
  2499.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors));
  2500. d291 1
  2501. a291 1
  2502.     MakeCheckSum(sunLabelPtr);
  2503. d294 6
  2504. a299 5
  2505.     printf("%c: First Cyl %4d Num Cyl %4d (Blocks %5d)\n",
  2506.         'a' + part,
  2507.         sunLabelPtr->map[part].cylinder,
  2508.         sunLabelPtr->map[part].numBlocks /
  2509.         (diskInfoPtr->numHeads * diskInfoPtr->numSectors),
  2510. d318 1
  2511. a318 1
  2512. SeeCheckSum(sunLabelPtr)
  2513. d331 1
  2514. a331 1
  2515. CheckCheckSum(sunLabelPtr)
  2516. d335 1
  2517. a335 1
  2518.         short count = DEV_BYTES_PER_SECTOR/sizeof(short);
  2519. d343 1
  2520. a343 1
  2521. MakeCheckSum(sunLabelPtr)
  2522. d349 1
  2523. d354 291
  2524. @
  2525.  
  2526.  
  2527. 1.1
  2528. log
  2529. @Initial revision
  2530. @
  2531. text
  2532. @d11 1
  2533. a11 1
  2534. static char rcsid[] = "$Header: labelDisk.c,v 1.1 88/06/02 13:23:34 brent Exp $ SPRITE (Berkeley)";
  2535. d65 1
  2536. a65 1
  2537.     Opt_PrintUsage(argv[0], numOptions, optionArray);
  2538. @
  2539.